-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Themes] Refactor CLI server events for Hot Reload (PoC Hot Reload for OSE) #4908
base: main
Are you sure you want to change the base?
Conversation
Coverage report
Show files with reduced coverage 🔻
Test suite run success2001 tests passing in 904 suites. Report generated by 🧪jest coverage report action from 8657282 |
/snapit |
🫰✨ Thanks @frandiox! Your snapshot has been published to npm. Test the snapshot by intalling your package globally: pnpm i -g @shopify/[email protected]
|
packages/theme/src/cli/utilities/theme-environment/hot-reload/client.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR, @frandiox 🔥 Amazing work as usual!
I couldn't spot any issues with themes neither theme app extension. Given the nature of this change tho, I'd love to expand these tests even further.
When we feel ready, I believe we can snapit
this branch and share a build with our partners to gather their feedback before the release. I'm sure they will love having hot reload on OSE, so we will likely have a wide audience.
Regarding these changes:
- Move the hot reload decisions from the server to the client. For example, instead of sending an event for "CSS update" from the server to the client, now the server sill simply say "here, this file has been changed". The client will check the extension of the file and decide to perform a CSS update, or something else.
This is very neat. The more I look at the client.ts
file, the more it feels like it should be a standalone library. I can see it being a dependency for the CLI and for the OSE/theme-preview, and I can also see third-party tooling being built on top of it.
Having that as a standalone library might also give us more room to separate the logic and version those APIs—keeping in mind that OSE won't have guarantees about the CLI version.
- The server now emits 2 events per file: once when the file is updated locally, and another one when it's uploaded to the cloud
This is an excellent decision! ✨
Please, let me know your thoughts about this! Thanks again for this PR!
packages/theme/src/cli/utilities/theme-environment/hot-reload/client.ts
Outdated
Show resolved
Hide resolved
packages/theme/src/cli/utilities/theme-environment/hot-reload/client.ts
Outdated
Show resolved
Hide resolved
…ors in OSE when CLI is not active
d0761c9
to
0579cf9
Compare
We detected some changes at packages/*/src and there are no updates in the .changeset. |
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/themes/types.d.ts@@ -4,18 +4,19 @@ import { AdminSession } from '../session.js';
*/
export type Key = string;
export type ThemeFSEventName = 'add' | 'change' | 'unlink';
+type OnSync = (onSuccess: () => void, onError?: () => void) => void;
type ThemeFSEvent = {
type: 'unlink';
payload: {
fileKey: Key;
- onSync?: (fn: () => void) => void;
+ onSync: OnSync;
};
} | {
type: 'add' | 'change';
payload: {
fileKey: Key;
onContent: (fn: (content: string) => void) => void;
- onSync: (fn: () => void) => void;
+ onSync: OnSync;
};
};
export type ThemeFSEventPayload<T extends ThemeFSEventName = 'add'> = (ThemeFSEvent & {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this PR, @frandiox! 🚀 It looks great! I believe we just need to handle those minor issues on the editor side, and then we can proceed with the merge here :)
Also, I've left a minor question about versioning events 🙇
@@ -50,6 +50,7 @@ | |||
"yaml": "2.7.0" | |||
}, | |||
"devDependencies": { | |||
"@shopify/theme-hot-reload": "^0.0.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should version the events here somehow? (in runtime)
This way, if we need to change something, we can prevent older versions of the CLI from breaking (we will likely need to keep triggering old events if we really change the shape of them)
/snapit |
🫰✨ Thanks @benjaminsehl! Your snapshot has been published to npm. Test the snapshot by intalling your package globally: pnpm i -g @shopify/[email protected]
|
Goals: support hot reload for Online Store Editor and Theme Preview.
Full context here.
The changes in this repo are:
🎩 :
shopify theme dev
and check that it downloads thetheme-hot-reload
script in the network tab.